package com.hitrust.gs.action;

import java.io.FileInputStream;
import javax.servlet.ServletOutputStream;

import com.hitrust.gs.service.GSBaseAction;
import com.hitrust.gs.service.GSBaseForm;
import com.hitrust.gs.service.GSBaseManager;
import com.hitrust.gs.lib.GSBaseConstants;
import com.hitrust.gs.lib.GSSystemConfigurator;

/**
 * 筛选不符合产品文件下载
 */
public class GSManufactureFilterUploadFileDownAction extends GSBaseAction 
{
	    
    public String execute(GSBaseForm aForm) throws Exception 
    {
        String tFilename=aForm.getRequest().getParameter("filename");

        String tPath=GSSystemConfigurator.getParam("gs.down.savepath")+"/"+tFilename;
        aForm.getResponse().setContentType( "application/ostream;charset=UTF-8");
        aForm.getResponse().setHeader("Content-disposition","attachment; filename=" +GSBaseManager.toUtf8String(tFilename));

        FileInputStream tInputStream = new FileInputStream(tPath);
        
        ServletOutputStream tOutputStream = aForm.getResponse().getOutputStream();
        byte[] buff = new byte[512];
        int readCount = 0;
        readCount = tInputStream.read(buff);
        while (readCount != -1)
        {
            tOutputStream.write(buff, 0, readCount);             
            readCount = tInputStream.read(buff);
        }
        tOutputStream.flush();
        if (tInputStream!=null){
            tInputStream.close();
        }
        if (tOutputStream!=null){
            tOutputStream.close();
        }
       
        return GSBaseConstants.FORWARD_SUCCESS;
    }    

}

